#include "ventilator.h"
#include "globalvar2.h"

#include "ohos_init.h"
#include "cmsis_os2.h"

void Ventilator_task(void)
{
    Ventilator_init(); //初始化门模块  
    printf("The door is activated successfully!!\r\n");
    usleep(100 * 1000);  //延时100ms
    while(1)
    {
        if(g_gas < 10 && g_gas > 0)
        {
            Ventilator_switch(1);
        }
        // if(g_gas_flag == 1)
        // {
        //     Ventilator_switch(1);
        // }
        else
        {
            Ventilator_switch(0);
        }
        // if(g_gas_flag == 0)
        // {
        //     Ventilator_switch(0);
        // }
        usleep(1 * 1000 * 1000);
    }
}

void Ventilator_entry(void)
{
	usleep(3 * 1000 * 1000); //延时3s
	osThreadAttr_t attr; //任务属性结构体
	attr.name = "Ventilator_task"; //任务名称
	attr.stack_size = 1024; //任务内存大小
	attr.priority = 25;
    if(osThreadNew((osThreadFunc_t)Ventilator_task, NULL, &attr) == NULL)
    {
        printf("[Ventilator] Falied to create Ventilator_task!\n");
    }
    printf("[Ventilator] Succeed to create Ventilator!\n");
}

SYS_RUN(Ventilator_entry);